// pages/module/promote/promote.js
import {
   search,
  //item_select,
  vity,
} from '../../../../utils/imapi.js';
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    items:[],
	img:'',
	background:'',
	top:'活动专区',
	is_load: false,
	page_index: 1,
	tabData:'',
	cur_scroll_top:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
	  console.log(options.keyword);
	  console.log(options.view_code);
	 const vv=await vity({view_code:options.view_code});
	 console.log(vv);
	  this.setData({
		  img:vv.data.banner_img,
		  background:vv.data.bg_color,
		  top:vv.data.url_type_name,
	  })
      const Hot=await search({q:options.keyword, page_index: 1, page_size: 10 });
	  
      console.log(Hot);
      this.setData({
         items:Hot.data,
		 tabData:options.keyword
	  })
     console.log(this.data.items);
  },
  onPageScroll: function (e) {
    var that = this;
   // console.log(e.scrollTop);
      that.setData({
        cur_scroll_top: e.scrollTop
      })
  
  },
  ducat(e){
	  console.log(e);
	  var p=e.currentTarget.dataset.id.p;
	  var id=e.currentTarget.dataset.id.item_id;
	  var index = e.currentTarget.dataset.index;
	  app.globalData.cur_product = this.data.items[index];
	  wx.navigateTo({
	      url: '/pages/module/productDetail/productDetail?id=' + id + '&p=' + p,
	  })
  },
  onReachBottom: async function () {
    var that = this;
  
    if ( this.data.is_load ) return;
	console.log('111');
	this.setData({
	  is_load: true
	})
	
	let { data } = await search({ q: this.data.tabData, page_index: this.data.page_index, page_size: 10 })
	let arr = data;
	
	  this.data.page_index++

	  this.setData({
	    is_load: false,
	    items: [...this.data.items, ...arr],
	  })
	
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})